﻿namespace TriangleGames.TrainResEditor
{
    using System;
    using System.Runtime.CompilerServices;
    using UnityEditor;
    using UnityEngine;

    [Serializable]
    internal class InspectorPanel
    {
        [CompilerGenerated]
        private Rect View__BackingField;
        private TriangleGames.TrainResEditor.InspectorMode inspectorMode;
        private readonly string[] inspectorModeLabels = new string[] { "状态机", "动作", "事件", "变量" };

        private void DoBottomToolbar()
        {
            GUILayout.BeginHorizontal(EditorStyles.toolbar, new GUILayoutOption[0]);
            bool flag = GUILayout.Toggle(FsmEditorSettings.ShowHints, "提示 [F1]", EditorStyles.toolbarButton, new GUILayoutOption[] { GUILayout.MaxWidth(100f) });
            if (flag != FsmEditorSettings.ShowHints)
            {
                FsmEditorSettings.ShowHints = flag;
                FsmEditorSettings.SaveSettings();
            }
            if (GUILayout.Button("设置", EditorStyles.toolbarButton, new GUILayoutOption[] { GUILayout.MinWidth(150f) }))
            {
                this.inspectorMode = TriangleGames.TrainResEditor.InspectorMode.Preferences;
            }
            GUILayout.EndHorizontal();
        }

        private void DoModeSelector()
        {
            TriangleGames.TrainResEditor.InspectorMode mode = (TriangleGames.TrainResEditor.InspectorMode) GUILayout.Toolbar((int) this.inspectorMode, this.inspectorModeLabels, FsmEditorStyles.ToolbarTab, new GUILayoutOption[0]);
            if (mode != this.inspectorMode)
            {
                this.SetMode(mode);
            }
        }

        public void OnGUI(Rect area)
        {
            GUILayout.BeginArea(area);
            if (EditorApplication.isPlaying && FsmEditorSettings.DisableInspectorWhenPlaying)
            {
                GUILayout.BeginHorizontal(EditorStyles.toolbar, new GUILayoutOption[0]);
                GUILayout.FlexibleSpace();
                GUILayout.EndHorizontal();
                GUILayout.Label("运行时观察器无效. 查看设置.", new GUILayoutOption[0]);
                FsmEditorSettings.DisableInspectorWhenPlaying = !GUILayout.Toggle(!FsmEditorSettings.DisableInspectorWhenPlaying, "运行时观察器有效", new GUILayoutOption[0]);
                if (GUI.changed)
                {
                    FsmEditorSettings.SaveSettings();
                }
                GUILayout.EndArea();
            }
            else
            {
                this.View = area;
                EditorGUIUtility.LookLikeControls(150f);
                GUILayout.BeginVertical(new GUILayoutOption[0]);
                this.DoModeSelector();
                switch (this.inspectorMode)
                {
                    case TriangleGames.TrainResEditor.InspectorMode.FsmInspector:
                        FsmInspector.OnGUI();
                        break;

                    case TriangleGames.TrainResEditor.InspectorMode.StateInspector:
                        FsmEditor.StateInspector.OnGUI();
                        break;

                    case TriangleGames.TrainResEditor.InspectorMode.EventManager:
                        FsmEditor.EventManager.OnGUI();
                        break;

                    case TriangleGames.TrainResEditor.InspectorMode.VariableManager:
                        FsmEditor.VariableManager.OnGUI();
                        break;

                    case TriangleGames.TrainResEditor.InspectorMode.Preferences:
                        FsmEditorSettings.OnGUI();
                        break;

                    case TriangleGames.TrainResEditor.InspectorMode.Watermarks:
                        WatermarkSelector.OnGUI();
                        break;
                }
                this.DoBottomToolbar();
                GUILayout.EndVertical();
                GUILayout.EndArea();
            }
        }

        public void ResetView()
        {
            switch (this.inspectorMode)
            {
                case TriangleGames.TrainResEditor.InspectorMode.StateInspector:
                    FsmEditor.StateInspector.Reset();
                    return;

                case TriangleGames.TrainResEditor.InspectorMode.EventManager:
                    FsmEditor.EventManager.Reset();
                    return;

                case TriangleGames.TrainResEditor.InspectorMode.VariableManager:
                    FsmEditor.VariableManager.Reset();
                    return;

                case TriangleGames.TrainResEditor.InspectorMode.Preferences:
                    break;

                case TriangleGames.TrainResEditor.InspectorMode.Watermarks:
                    WatermarkSelector.ResetSelection();
                    break;

                default:
                    return;
            }
        }

        public void SetMode(TriangleGames.TrainResEditor.InspectorMode mode)
        {
            if (this.inspectorMode != mode)
            {
                FsmEditor.ResetKeyboard();
                this.inspectorMode = mode;
                this.ResetView();
                switch (this.inspectorMode)
                {
                    case TriangleGames.TrainResEditor.InspectorMode.FsmInspector:
                        FsmInspector.Init();
                        return;

                    case TriangleGames.TrainResEditor.InspectorMode.StateInspector:
                    case TriangleGames.TrainResEditor.InspectorMode.EventManager:
                    case TriangleGames.TrainResEditor.InspectorMode.VariableManager:
                    case TriangleGames.TrainResEditor.InspectorMode.Preferences:
                        return;

                    case TriangleGames.TrainResEditor.InspectorMode.Watermarks:
                        WatermarkSelector.Init();
                        return;
                }
            }
        }

        public void Update()
        {
            if (!EditorApplication.isPlaying || !FsmEditorSettings.DisableInspectorWhenPlaying)
            {
                if ((this.inspectorMode == TriangleGames.TrainResEditor.InspectorMode.Watermarks) && (FsmEditor.SelectedFsm == null))
                {
                    this.SetMode(TriangleGames.TrainResEditor.InspectorMode.FsmInspector);
                }
                switch (this.inspectorMode)
                {
                    case TriangleGames.TrainResEditor.InspectorMode.FsmInspector:
                        FsmInspector.Update();
                        return;

                    case TriangleGames.TrainResEditor.InspectorMode.StateInspector:
                        FsmEditor.StateInspector.Update();
                        return;
                }
            }
        }

        public TriangleGames.TrainResEditor.InspectorMode Mode
        {
            get
            {
                return this.inspectorMode;
            }
        }

        public Rect View
        {
            [CompilerGenerated]
            get
            {
                return this.View__BackingField;
            }
            [CompilerGenerated]
            private set
            {
                this.View__BackingField = value;
            }
        }
    }
}

